<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <!--sweetalert2-->
    <link href="./sweetalert2/dist/sweetalert2.min.css" rel="stylesheet">
    <script src="./sweetalert2/dist/sweetalert2.min.js" type="text/javascript"></script>
</head>
<body>


<script>


//async  修饰的函数是异步函数
    async  function fn(){
        const ipAPI = './json/2.txt'

        const inputValue = fetch(ipAPI).then(function (response){
                return response.json();
            })                                    //response => response.json()
            .then(data => data.ip)

        const p = await Swal.fire({                  //   await 必须使用在  async修饰的函数中  拿到promise函数的执行结果
            title: '请输入姓名',
            input: 'text',
            inputLabel: '你的名字',
            inputValue: inputValue,
            showCancelButton: true,
            cancelButtonText:'取消',
            confirmButtonText: '确认',
            inputValidator: (value) => {
                if (!value) {
                    return 'You need to write something!'
                }
            }
        })

        console.log(p)

        if (p.value) {         //任何字符串除了空 都是 true   boolean('鲁大师')=true
            Swal.fire({
                title: p.value,
                confirmButtonText: '确认',
            })
        }else{
            alert('false')
        }
    }


    fn()
</script>
</body>
</html>